variable = {
	
}

//pl is the actual player in library
//plid is the UniqueID in library
library = {
	joystick = {
		Get = [[function(uid,nopod) //THIS IS NOT FOR NORMAL USE, USE reg:Get() WHERE reg IS RETURNED FROM joystick.register INSTEAD
			local joystick = _G.joystick
			if not joystick then
				return
			end
			
			if not nopod then
				if IsEntity(self) and self:IsVehicle() then
					local pl = self:GetPassenger()
					if pl and IsEntity(pl) and pl:IsPlayer() and pl:IsConnected() then
						return joystick.Get(pl,uid)
					end
					return false
				end
			elseif pl and IsEntity(pl) and pl:IsPlayer() and pl:IsConnected() then
				return joystick.Get(pl,uid)
			end
			
			return 0
		end]],
	},
	_joystick = {
		Get = [[function(this,nopod)
			local uid = this.uid
			local ret = joystick.Get(uid,nopod)
			
			if ret then
				return ret*(this.max-this.min)/255+this.min
			else
				return this.default,false
			end
		end]]
	},
}

//_pl is the UniqueID in execute
execute = [[
	joystick.register = function(uid,type,desc,min,max,default)
		local jcon = _G.jcon
		if not jcon then
			return
		end
		
		local uid = _pl.."_"..tostring(uid)
		local type = type or "analog"
		local desc = desc or uid or "Generic"
		local min = tonumber(min) or 0
		local max = tonumber(max) or 255
		local default = default or min
		
		local uidvalid,uiderror = jcon.isValidUID(uid)
		if not uidvalid then
			ErrorNoHalt("Wire Joystick: "..tostring(uiderror).."\n")
			return false
		end
		
		local out = {}
		
		jcon.unregister(uid)
		jcon.register{
			uid = uid,
			type = type,
			description = desc,
			category = "LC ".._pl,
			min = 0,
			max = 255,
		}
		out.uid = uid
		out.min = min
		out.max = max
		out.default = default
		
		local meta = {
			__index = _joystick,
			__newindex = ErrorNoHalt,
		}
		setmetatable(out,meta)
		
		return out
	end
]]